//============================================================================
// Name        : gpioThread.cpp
// Author      : O.M.A.V.
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <pthread.h>
#include "gpioAansturen.h"


#define LEDHIGH_1  	gpio->portHigh(7);
#define LEDLOW_1	gpio->portLow(7);
#define LEDHIGH_2  	gpio->portHigh(6);
#define LEDLOW_2	gpio->portLow(6);
#define LEDHIGH_3 	gpio->portHigh(5);
#define LEDLOW_3	gpio->portLow(5);
#define LEDHIGH_4  	gpio->portHigh(2);
#define LEDLOW_4	gpio->portLow(2);

using namespace std;

int pwm1 = 1;
int pwm2 = 2;
int pwm3 = 3;
int pwm4 = 4;

gpioAansturen *gpio;


void *threadpwm1(void *threadid)
{
	while(true)
	{
		sleep(pwm1);
		LEDHIGH_1
		sleep(pwm1);
		LEDLOW_1
	}
	pthread_exit(NULL);
}
void *threadpwm2(void *threadid)
{
	while(true)
	{
		sleep(pwm2);
		LEDHIGH_2
		sleep(pwm2);
		LEDLOW_2
	}
	pthread_exit(NULL);
}
void *threadpwm3(void *threadid)
{
	while(true)
	{
		sleep(pwm3);
		LEDHIGH_3
		sleep(pwm3);
		LEDLOW_3
	}
	pthread_exit(NULL);
}
void *threadpwm4(void *threadid)
{
	while(true)
	{
		sleep(pwm4);
		LEDHIGH_4
		sleep(pwm4);
		LEDLOW_4
	}
	pthread_exit(NULL);
}
int main() {

	gpio = new gpioAansturen();

	gpio->installOutput(7);
	gpio->installOutput(6);
	gpio->installOutput(5);
	gpio->installOutput(2);
	pthread_t thread;
	pthread_create(&thread, NULL, threadpwm1, NULL);
	pthread_create(&thread, NULL, threadpwm2, NULL);
	pthread_create(&thread, NULL, threadpwm3, NULL);
	pthread_create(&thread, NULL, threadpwm4, NULL);

	while(true)
	{

	}
	return 0;
}
